import { _decorator, Component, Node } from 'cc';
import { BaseGame } from '../extensions/cocos-scaffold-3x/assets/BaseGame';
import { RandomPseudo } from '../extensions/cocos-scaffold-3x/assets/common/RandomPseudo';
import { GameStorage } from '../extensions/cocos-scaffold-3x/assets/GameStorage';
import { ConfigManager } from '../extensions/cocos-scaffold-3x/assets/manger/ConfigManager';
import { LocalStorageManager } from '../extensions/cocos-scaffold-3x/assets/manger/LocalStorageManager';
import { LoggerManager } from '../extensions/cocos-scaffold-3x/assets/manger/LoggerManager';
import { OpenViewOptions, UIManager } from '../extensions/cocos-scaffold-3x/assets/manger/UIManager';
import { BaseView } from '../extensions/cocos-scaffold-3x/assets/ui/base/BaseView';
const { ccclass, property } = _decorator;

export class Game extends BaseGame {
    static GAME_VERSION: string = "v0.0.1";

    static isDebug: boolean = false

    random = new RandomPseudo(123)
    constructor() {
        super();
    }

    onInitComplete(): void {

    }

    update(dt: number) {
        super.update(dt)
    }

    //#region 管理器中一些常用的操作，快捷方法放这里

    /**打开视图 */
    openView(viewClzOrViewId: (new () => BaseView) | number, options: OpenViewOptions = {}) {
        return this.uiMgr.openView(viewClzOrViewId, options)
    }

    /**获取本地数据 */
    storage<T extends GameStorage<any>>(storageClz: (new () => T)) {
        return this.localStoreMgr.storage(storageClz)
    }
    /**
     * 获取对象型配置表
     * @param config 
     * @returns 
     */
    mapCfg<T>(config: ((new () => T))): T {
        return this.cfgMgr.mapCfg(config)
    }
    /**
     * 获取列表型配置表中的一行
     * @param config 
     * @returns 
     */
    cfgById<T>(config: ((new () => T)), id: number | string): T {
        return this.cfgMgr.cfgById(config, id)
    }
    /**
    * 获取列表型配置表中的所有行
    * @param config 
    * @returns 
    */
    cfgArr<T>(config: ((new () => T))): T[] {
        return this.cfgMgr.cfgArr(config)
    }

    //#endregion


    //#region 获取一些常用的管理器的快捷方法
    /**配置表管理器 */
    get cfgMgr() {
        return this.mgr(ConfigManager)
    }
    /**ui管理器 */
    get uiMgr() {
        return this.mgr(UIManager)
    }
    
    /**日志管理器 */
    get logMgr() {
        return this.mgr(LoggerManager)
    }
    /**本地存储管理器 */
    get localStoreMgr() {
        return this.mgr(LocalStorageManager)
    }
    //#endregion
}

export const gg = new Game()

export enum EBundleName {
    resources = "resources",
    home = "home",
    subBundle = "subBundle",
}
